<?php

namespace app\common\model\shop;

use think\Model;


class Ordergoods extends Model
{





    // 表名
    protected $name = 'shop_ordergoods';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'goods_info_json'
    ];



    public function getGoodsInfoJsonAttr($value, $data)
    {
        if (isset($data['goods_info'])) {
            $arr = json_decode($data['goods_info'], 1);
            if($arr && !empty($arr['content'])){
                unset($arr['content']);
            }
            
            return $arr ?? [];
        }
        return [];
    }







    public function order()
    {
        return $this->belongsTo('Order', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
